package com.njtoyo.taxi.admin.mapper.secondary.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njtoyo.taxi.admin.library.Const;
import com.njtoyo.taxi.admin.mapper.secondary.entity.Resource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 资源表 Mapper 接口
 * </p>
 *
 * @author Dell
 * @since 2021-06-17
 */
@Repository
@DS(Const.SECONDARY_DS)
public interface ResourceMapper extends BaseMapper<Resource> {

    @Select("SELECT id FROM resource WHERE parent_id = #{id}")
    List<Long> getChildrenIdsById(@Param("id") Long id);

    @Select("UPDATE resource SET sort = #{sort}, parent_id = #{parentId} WHERE id = #{id}")
    Boolean updateSortById(@Param("parentId") Long parentId, @Param("id") Long id, @Param("sort") Integer sort);

}
